package com.okami.domain.customer;

import com.okami.common.AbstractEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.data.domain.AfterDomainEventPublication;
import org.springframework.data.domain.DomainEvents;

import javax.persistence.*;
import java.util.Collection;
import java.util.Set;

/**
 * @author: TanJingyu
 * @create: 2020-12-19 11:18
 **/
@EqualsAndHashCode(callSuper = true)
@Entity
@Table
@Data
@Accessors(chain = true)
public class User extends AbstractEntity<Long> {
    private String userName;
    private Integer age;
    @OneToMany(mappedBy = "user")
    private Set<BankCard> bankCards;

//    /**
//     *  碰到@OneToMany
//     *  user_id字段作为外键维护在多的一方
//     *  若想使用中间表维护，则不添加@JoinColumn
//     */
//    @JoinColumn(name = "user_id")
//    @OneToMany(targetEntity = BankCard.class)
//    private Set<BankCard> bankCards;

    /**
     *  ApplicationEvent特殊
     * @return
     */
    @DomainEvents
    User domainEvents() {
        System.out.println("事件发生了");
        return this;
    }

    @AfterDomainEventPublication
    void callbackMethod() {
        System.out.println("事件之后了啊");
    }

}
